<?php
class Admin_Model_Banner extends Zend_Db_Table{
	protected $_name = 'banner';
	protected $_primary = 'id';


	public function getAll($order="desc"){
		
		$db = Zend_Registry::get ( 'connectDb' );
		
		$select = $db->select ()->from ( array ('r' => 'banner' ) )
			;
		
		if ($order != "desc")
			$select = $select->order ( "r.time_post" );
		else
			$select = $select->order ( "r.time_post desc" );
		$stmt = $select->query ();
		$result = $stmt->fetchAll ();
		return $result;
		
	}
	public function updatePage($arrParam){
		$data=array('title'=>$arrParam['title'],
				'image'=>$arrParam['image'],
				'desription'=>$arrParam['description'],
				'category_id'=>$arrParam['category_id'],
				'content'=>$arrParam['content']);
		$where = 'id = ' . $arrParam['page_id'];
		$this->update($data, $where);
		
	}
	public function getBanner($arrParam){
		$se = $this->select ();
		$se->where ( "id= ?", $arrParam['id'] );
		
		return $this->fetchRow ( $se )->toArray ();
		
	}

	public function deleteBanner($arrParam = null){
		$where = $this->getAdapter ()->quoteInto ( 'id = ?', $arrParam ["id"] );
		$this->delete ( $where );
	
	}
	public function editBanner($arrParam) {
		$where = 'id = ' . $arrParam ['id'];
	
		$row = $this->fetchRow ( $where );
		$row->link = $arrParam ['link'];
		$row->image = $arrParam ['image'];
		$row->discription = $arrParam ['discription'];
		
		$row->time_post = date ( "Y-m-d H:i:s" );
		$row->save ();
	}
	public function addBanner($arrParam) {
		$row = $this->fetchNew ();
		$row->link = $arrParam ['link'];
		$row->image = $arrParam ['image'];
		$row->discription = $arrParam ['discription'];
		
		$row->time_post = date ( "Y-m-d H:i:s" );
		$row->save ();
	}


}